﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLib.Accounts.Bus;
using System.Data;
namespace Ewts.Storage
{
    public partial class FinaceData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                databing();
            }
        }
        protected void databing()
        {
            User curUser = new User();
            curUser = (User)Session["UserInfo"];
            string belongarea = curUser.CompanyCity;

            string where = "belongarea='" + belongarea + "' and left(loadnum,2)='86'";

            DataTable dt = new DataLib.BLL.LoadNum().GetList(where).Tables[0];

            DataTable data = new DataTable();
            data.Columns.Add("LoadNumid");
            data.Columns.Add("LoadNumNo");
            data.Columns.Add("CustomerCode");
            data.Columns.Add("CustomerName");
            data.Columns.Add("CollecMoneyDate");
            data.Columns.Add("InvoiceDate");
            data.Columns.Add("PayDate");
            data.Columns.Add("CollecInvoiceDate");

            foreach (DataRow row in dt.Rows)
            {
                DataRow dr = data.NewRow();
                dr["LoadNumNo"] = row["loadnum"];
                dr["LoadNumid"] = row["id"];
                DataLib.Model.Cumtomer cum = new DataLib.BLL.Cumtomer().GetModel(Convert.ToInt32(row["customerid"]));

                dr["CustomerCode"] = cum.customercode;
                dr["CustomerName"] = cum.companyname;

                DataTable dtemp = new DataLib.BLL.FinaceData().GetList(" LoadNumID=" + Convert.ToInt32(row["id"])).Tables[0];

                if (dtemp.Rows.Count>0&&dtemp!=null)
                {
                    dr["CollecMoneyDate"] = dtemp.Rows[0]["CollecMoneyDate"];
                    dr["InvoiceDate"] = dtemp.Rows[0]["InvoiceDate"];
                    dr["PayDate"] = dtemp.Rows[0]["PayDate"];
                    dr["CollecInvoiceDate"] = dtemp.Rows[0]["CollecInvoiceDate"];
                }
                string where1=" LoadNumID=" + Convert.ToInt32(row["id"]);
                DataTable dtemp1 = new DataLib.BLL.BillsConfirm().GetList(where1).Tables[0];
                if (dtemp1.Rows.Count>0&&dtemp1!=null)
                {
                    if (dtemp1.Rows[0]["CEDate"].ToString()=="零结算" && dtemp1.Rows[0]["CADateInvice"].ToString()=="零结算")
                    {
                        row["CollecMoneyDate"] = "零结算";
                        row["InvoiceDate"] = "零结算";
                        row["PayDate"] = "零结算";
                        row["CollecInvoiceDate"] = "零结算";
                    }
                }
                data.Rows.Add(dr);
            }
            rept.DataSource = data;
            rept.DataBind();
        }
    }
}